#!/usr/bin/env python
from pathlib import Path
import random
import shutil
p1=Path('/home/python/projects/py369/temp/a/b/c/d')
p1.mkdir(parents=True,exist_ok=True)
p2=Path('/home/python/projects/py369/temp/a')
Str1='abcdefghijklmnopqrstuvwxyz'
for i in range(50):
    randomint=random.randint(1,4)
    p3=p2.glob('**')
    for j in range(randomint):
        p4=next(p3)
    filename='{}.txt'.format(''.join([random.choice(Str1) for n in range(4)]))
    p5=p4 / filename
    p5.touch()
src='/home/python/projects/py369/temp/a'
dst='/home/python/projects/py369/dst'
shutil.rmtree(dst,ignore_errors=True)
def ignore(src,names):
    return {name for name in names if not name.startswith('x') and not name.startswith('y') and not name.startswith('z') and name.endswith('txt')}
# 这里这一连串的逻辑判断可以改为if nname[0] not in 'xyz'

shutil.copytree(src,dst,ignore=ignore)















